﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using BLL;
using BLL.Managers;

namespace CorporateGymManagementSystem
{
    /// <summary>
    /// Interaction logic for MessageBoardWindow.xaml
    /// </summary>
    public partial class MessageBoardWindow : Window
    {
        private List<Message> messageBoardMessages;
        private GymWorker loggedInUser;

        public MessageBoardWindow(GymWorker loggedInUser)
        {
            InitializeComponent();
            this.loggedInUser = loggedInUser;
            populateMessageBoard();
        }

        private void populateMessageBoard()
        {
            messageBoardMessages = MessagesManager.Instance.GetMessageBoardMessages();
            messageBoardMessages.Sort(new MessageDateComparer());

            foreach (Message message in messageBoardMessages)
            {
                messageBoardPreview messagePreview = new messageBoardPreview();
                messagePreview.Margin = new Thickness(1, 1, 1, 1);
                messagesStackPanel.Children.Add(messagePreview);
                messagePreview.SetMessageToPreview(message);
            }
        }

        private void composeMessageBoardMessageButton_Click(object sender, RoutedEventArgs e)
        {
            ComposeNewMessageWindow newMessageWindow = new ComposeNewMessageWindow(loggedInUser, eComposeType.MessageBoardMessage);
            newMessageWindow.ShowDialog();
            messagesStackPanel.Children.Clear();
            populateMessageBoard();
        }
    }
}
